package com.androidvizlab.bachelor.customcomponents.listenersandadapters;

import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;

/**
 * A class that implements TextWatcher interface.
 * This is use to insure that all required text field(EditText) are
 * filled and all values are valid before the user can submit 
 * the data to the server.
 * 
 * @author The Hive
 *
 */
public class CustomTextChangedListener implements TextWatcher{

	private EditText editText;
	private final static String ERROR_FIELD_REQUIRED = "This field is required";
	
	//([a-zA-Z]:(\\w+)*\\[a-zA-Z0_9]+)?.exe
	//^(?:[a-zA-Z]\:|\\\\[\w\.]+\\[\w.]+)\\(?:[\w]+\\)*\w([\w.])+$
	
	public CustomTextChangedListener()
	{
		
	}
	
	@Override
	public void afterTextChanged(Editable arg0) {
		
		if(editText != null && arg0.length() == 0)
		{
			editText.setError(ERROR_FIELD_REQUIRED);
		}
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		
	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		
	}
	
	//GETTERS AND SETTERS

	public EditText getEditText() {
		return editText;
	}

	public void setEditText(EditText editText) {
		this.editText = editText;
	}
}
